<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&#160;">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- The URL of the TFS server that's the source of the XML document this stylesheet will transform. -->
  <xsl:param name="tfsUrl"/>
  <xsl:output method="html" encoding="UTF-8"/>
  <xsl:template match="/">
    <html>
      <head>
        <style>
          body {background-color:#ffffff; font-family:Calibri;}
          .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em}
          .pathname {font-family:Consolas; float:right;}
          .fileheader {margin-bottom:.5em; font-weight:bolder}
          .diff {margin:0; font-family:Consolas;}
          .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
          .tasklist ul {margin-top:0;margin-bottom:0;}
          tr.alt {background-color:#eeeeee}
          #added {background-color:#ddffdd;}
          #addedchars {background-color:#99ff99;font-weight:bolder;}
          tr.alt #added {background-color:#ccf7cc;}
          #removed {background-color:#ffdddd;}
          #removedchars {background-color:#ff9999;font-weight:bolder;}
          tr.alt #removed {background-color:#f7cccc;}
          #info {color:#888888;}
          #context {background-color:#eeeeee;}
          table.WithBorder { border-style: solid; border-color: #F1EFE2; border-width: 1px; border-collapse: collapse; }
          td.ColHeading { font-size: x-small; border-style: solid; border-color: #F1EFE2; border-width: 1px; background: #F1EFE2; width: auto; }
          td.ColData { font-size: x-small; border-style: solid; border-color: #F1EFE2; border-width: 1px; }
          td {padding-left:.3em;padding-right:.3em;}
          tr.head {border-bottom-width:1px;border-bottom-style:solid;font-weight:bolder;}
          tr.head td {padding:0;padding-top:.2em;}
          tr.diff {font-size:smaller;}
          .task {background-color:#ffff00;}
          .comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd;font-family:Consolas;}
          .error {color:red;}
          hr {border-width:0px;height:2px;background:black;}
          tt {font-family:Consolas}
          .workitem {margin-top:.5em; font-weight:bolder}
          .truncated {color:#ff2222; font-weight:bolder;}
        </style>
        <title>
          Checkin <xsl:value-of select="/checkin/changeset/@id"/> - <xsl:value-of select="$tfsUrl"/>
        </title>
      </head>
      <body>

        <table cellspacing="0" cellpadding="0" border="0" rules="cols">
          <tr class="head">
            <td colspan="2" >
              <a>
                <xsl:attribute name="href">
                  <xsl:value-of select="$tfsUrl"/>/VersionControl/Changeset.aspx?artifactMoniker=<xsl:value-of select="/checkin/changeset/@id"/>&amp;webView=true
                </xsl:attribute>
                <xsl:value-of select="/checkin/changeset/@project"/> Changeset <xsl:value-of select="/checkin/changeset/@id"/>
              </a>
            </td>
          </tr>
          <tr>
            <td>
              Checked in by:
            </td>
            <td>
              <xsl:value-of select="/checkin/changeset/@committer"/>
            </td>
          </tr>
          <tr>
            <td>
              Check-in date:
            </td>
            <td>
              <xsl:value-of select="/checkin/changeset/@commitDate"/>
            </td>
          </tr>
        </table>

        <br/>
        <pre class="comment">
          <xsl:value-of select="/checkin/changeset/comment"/>
        </pre>

        <xsl:if test="/checkin/changeset/workItem">
          <div class="workitem">
            Associated Work Items
          </div>
          <table cellspacing="0" cellpadding="2" border="0" rules="cols" class="WithBorder">
            <tr class="head">
              <td class="ColHeading">Type</td>
              <td class="ColHeading">Id</td>
              <td class="ColHeading">Title</td>
              <td class="ColHeading">Status</td>
              <td class="ColHeading">Assigned to</td>
            </tr>
            <xsl:for-each select="/checkin/changeset/workItem">
              <tr>
                <xsl:if test="position() mod 2 = 0">
                  <xsl:attribute name="class">alt</xsl:attribute>
                </xsl:if>
                <td class="ColData">
                  <xsl:value-of select="@type"/>
                </td>
                <td class="ColData">
                  <a>
                    <xsl:attribute name="href">
                      <xsl:value-of select="$tfsUrl"/>/WorkItemTracking/WorkItem.aspx?artifactMoniker=<xsl:value-of select="@id"/>
                    </xsl:attribute>
                    <xsl:value-of select="@id"/>
                  </a>
                </td>
                <td class="ColData">
                  <xsl:value-of select="@title"/>
                </td>
                <td class="ColData">
                  <xsl:value-of select="@state"/>
                </td>
                <td class="ColData">
                  <xsl:value-of select="@assignedTo"/>
                </td>
              </tr>
            </xsl:for-each>
          </table>
        </xsl:if>

        <xsl:if test="/checkin/changeset/policyOverride">
          <div class="workitem">
            Policy Overrides
          </div>
          <p>
            <xsl:value-of select="/checkin/changeset/policyOverride/@comment"/>
          </p>
          <table cellspacing="0" cellpadding="2" border="0" rules="cols" class="WithBorder">
            <tr class="head">
              <td class="ColHeading">Policy</td>
              <td class="ColHeading">Message</td>
            </tr>
            <xsl:for-each select="/checkin/changeset/policyOverride/policyFailure">
              <tr>
                <xsl:if test="position() mod 2 = 0">
                  <xsl:attribute name="class">alt</xsl:attribute>
                </xsl:if>
                <td class="ColData">
                  <xsl:value-of select="@policy"/>
                </td>
                <td class="ColData">
                  <xsl:value-of select="@message"/>
                </td>
              </tr>
            </xsl:for-each>
          </table>
        </xsl:if>

        <div class="workitem">
          Items
        </div>
        <table cellspacing="0" cellpadding="2" border="0" rules="cols" class="WithBorder">
          <tr class="head">
            <td class="ColHeading">
              Item path
            </td>
            <td class="ColHeading">
              Action
            </td>
            <td class="ColHeading" colspan="2">
              Changes
            </td>
          </tr>
          <xsl:for-each select="/checkin/item">
            <tr>
              <xsl:if test="position() mod 2 = 0">
                <xsl:attribute name="class">alt</xsl:attribute>
              </xsl:if>
              <td>
                <tt>
                  <!-- Only generate a link for the file name if we have more information for it below -->
                  <xsl:if test="@insertedLines or @deletedLines">
                    <a href="#file{position()}">
                      <xsl:value-of select="@path"/>
                    </a>
                  </xsl:if>
                  <xsl:if test="not( @insertedLines or @deletedLines )">
                    <xsl:value-of select="@path"/>
                  </xsl:if>
                </tt>
              </td>
              <td align="right">
                <tt>
                  <xsl:value-of select="@change"/>
                </tt>
              </td>
              <xsl:if test="not( @insertedLines or @deletedLines )">
                <td align="right" colspan="2">
                  <tt>
                    <xsl:if test="@type = 'Folder'">
                      [Folder]
                    </xsl:if>
                    <xsl:if test="not( @type = 'Folder' )">
                      [Binary file]
                    </xsl:if>
                  </tt>
                </td>
              </xsl:if>
              <xsl:if test="@insertedLines or @deletedLines">
                <td align="right" id="added">
                  <tt>
                    <xsl:if test="@insertedLines">
                      +<xsl:value-of select="@insertedLines"/>
                    </xsl:if>
                    <xsl:if test="not(@insertedLines)">
                      +0
                    </xsl:if>
                  </tt>
                </td>
                <td align="right" id="removed">
                  <tt>
                    <xsl:if test="@deletedLines">
                      -<xsl:value-of select="@deletedLines"/>
                    </xsl:if>
                    <xsl:if test="not(@deletedLines)">
                      -0
                    </xsl:if>
                  </tt>
                </td>
              </xsl:if>
            </tr>
          </xsl:for-each>
          
          <!-- Display the total number of added/deleted lines in the changeset -->
          <xsl:if test="/checkin/itemTotals">
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td align="right" id="added">
                <tt>
                  +<xsl:value-of select="/checkin/itemTotals/@totalAddedLines"/>
                </tt>
              </td>
              <td align="right" id="removed">
                <tt>
                  -<xsl:value-of select="/checkin/itemTotals/@totalDeletedLines"/>
                </tt>
              </td>
            </tr>
          </xsl:if>
          
          <xsl:if test="/checkin/changeset/@itemsTruncated">
            <tr>
              <td colspan="4" class="truncated">
                <xsl:value-of select="/checkin/changeset/@itemsTruncated"/> additional items included in the changeset.
              </td>
            </tr>
          </xsl:if>
        </table>

        <!-- Only include this section if we actually have any code highlights to display -->
        <xsl:if test="/checkin/item/difference/line[@highlightText]">
          <div class="workitem">
            Code Highlights
          </div>
          <div class="tasklist">
            <ul>
              <xsl:for-each select="/checkin/item/difference/line[@highlightText]">
                <li>
                  <a>
                    <xsl:attribute name="href">#item<xsl:value-of select="ancestor::node()[name()='item']/@id"/>line<xsl:value-of select="@lineNumber"/></xsl:attribute>
                    <xsl:value-of select="@highlightText"/>
                  </a>
                </li>
              </xsl:for-each>
            </ul>
          </div>
        </xsl:if>
        
        <hr/>

        <xsl:for-each select="/checkin/item[difference]">
          <a name="file{position()}"/>
          <div class="file">
            <div class="fileheader">
              <xsl:value-of select="@path"/>
            </div>
            <xsl:for-each select="./difference">
              <pre class="diff"><small id="info"><xsl:value-of select="@summary"/></small></pre>
              <xsl:for-each select="line">
                <xsl:if test="@highlightText">
                  <a>
                    <xsl:attribute name="name">item<xsl:value-of select="ancestor::node()[name()='item']/@id"/>line<xsl:value-of select="@lineNumber"/></xsl:attribute>
                  </a>
                </xsl:if>
                <xsl:if test="@type = 'Context'">
                  <pre class="diff" id="context">&nbsp;<xsl:value-of select="."/></pre>
                </xsl:if>
                <xsl:if test="@type = 'Deleted'">
                  <pre class="diff" id="removed">-<xsl:value-of select="."/></pre>
                </xsl:if>
                <xsl:if test="@type = 'Added'">
                  <pre class="diff" id="added">+<xsl:value-of select="."/></pre>
                </xsl:if>
              </xsl:for-each>
            </xsl:for-each>
            <xsl:if test="@truncated = 'True'">
              <p class="truncated">File listing truncated, too many lines</p>
            </xsl:if>
          </div>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>